<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <canvas id="canvas" style="border: 1px solid red"></canvas>
    <script>
      const canvas = document.getElementById("canvas");
      const ctx = canvas.getContext("2d");

      // 声明绘制一条新路径
      ctx.beginPath();
      // 设置起点
      ctx.moveTo(10, 10);
      // 设置线条宽度
      ctx.lineWidth = 5;
      // 设置线条两端样式
      ctx.lineCap = "round";
      // 设置颜色
      ctx.strokeStyle = "red";
      // 设置终点
      ctx.lineTo(100, 100);
      // 绘制
      ctx.stroke();
    </script>
  </body>
</html>
